package com.esdk.utils;

import com.esdk.esdk;

import java.util.Objects;

public class ComparableArray implements Comparable<ComparableArray>{
  public Object[] arr;
  public ComparableArray(Object[] array){
    this.arr=array;
  }
  @Override
  public int compareTo(ComparableArray obj){
    if(Objects.equals(arr,obj))
      return 0;
    if(obj==null||!(obj instanceof ComparableArray))
      return 1;
    return compareTo(obj,0,arr.length);
  }

  protected int compareTo(Object obj,int start,int end){
    int result=0;
    Object[] arr1;
    if(obj instanceof ComparableArray)
      arr1 =((ComparableArray)obj).arr;
    else if(obj instanceof Object[])
      arr1=(Object[])obj;
    else{
      arr1=esdk.array.EmptyIntArr;
      result=1;
    }
    for(int i=start,n=esdk.math.min(arr.length,arr1.length,end);i<n;i++){
      result=esdk.obj.compareTo(arr[i],arr1[i]);
      if(result!=0)
        break;
    }
    return result;
  }

  @Override
  public String toString(){
    return esdk.str.valueOf(arr);
  }
}
